/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controldepuntos.pantallas;

import controldepuntos.clases.AdministradorVentanas;
import controldepuntos.clases.TcReglamento;
import controldepuntos.clases.TrAlumno;
import controldepuntos.clases.TrIncidente;
import controldepuntos.clases.Utilidades;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Time;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author DIANA
 */
public class ModificarIncidencia extends javax.swing.JFrame {
    private static Integer idReglamento;
    private static Integer puntosPorIncidencias=0;
    private static Integer puntosRestantes=0;
    Object idSeleccionado=0;
    int filaSeleccionada=0;
    ArrayList<TcReglamento> listaReglamento = new ArrayList<>();
    /**
     * Creates new form AltaIncidencias
     */
    public ModificarIncidencia() {
        initComponents();
        if(Utilidades.numeroDeControl!=null){
            cargarIncidentesAlumno();
            cargarDatosAlumno();
            cargarCatalogoDeFaltas();
        }
    }
     
    public String obtenerDescripcionDeReglamentoPorId(Integer idReglamento){
        try{
            String descripcion=null;
            for(TcReglamento reglamentoActual : listaReglamento){
                if(reglamentoActual.getIdReglamento()==idReglamento){
                    descripcion=reglamentoActual.getDescripcion();
                }
            }
            return descripcion;
        }catch(Exception ex){
            return null;
        }
    }
    public Integer obtenerIdDeReglamentoSeleccionado(String elementoSeleccionado){
        try{
            Integer id=null;
            for(TcReglamento reglamentoActual : listaReglamento){
                if(reglamentoActual.getDescripcion()==elementoSeleccionado){
                    id=reglamentoActual.getIdReglamento();
                }
            }
            return id;
        }catch(Exception ex){
            return null;
        }
    }
    public void cargarCatalogoDeFaltas(){
        try{
            TcReglamento reglamento = new TcReglamento();
            listaReglamento = reglamento.seleccionarTodo();
            for(TcReglamento reglamentoActual : listaReglamento){
                cmbTipo.addItem(reglamentoActual.getDescripcion());
            }
            cmbTipo.setSelectedIndex(0);
        }catch(Exception ex){
            JOptionPane.showMessageDialog(this, ex.getMessage()+ex.getStackTrace(),"Error",JOptionPane.ERROR_MESSAGE);
        }
    }
     public void cargarIncidentesAlumno(){
        try{
            //Resetear valores de puntos para que no se sumen con los anteriores
            puntosPorIncidencias=0;
            puntosRestantes=0;
            DefaultTableModel model = new DefaultTableModel(){ 
            public boolean isCellEditable(int rowIndex,int columnIndex){return false;} };
            TrIncidente trIncidente = new TrIncidente();
            ResultSet rs = trIncidente.buscarTodoPorNumeroDeControlResultSet(Utilidades.numeroDeControl.toString());
            ResultSetMetaData rsmd = rs.getMetaData();
            int numeroDeColumnas = rsmd.getColumnCount();
            for(int i=1;i<=numeroDeColumnas;i++){
                model.addColumn(rsmd.getColumnLabel(i));
            }
            while(rs.next()){
                Object[] fila = new Object[numeroDeColumnas];
                puntosPorIncidencias=puntosPorIncidencias+rs.getInt("puntos");
               for(int i=0;i<numeroDeColumnas;i++){
                   fila[i]=rs.getObject(i+1);
               }
               model.addRow(fila);
            }
            tblIncidentes.setModel(model);
            jLabel15.setText(puntosPorIncidencias.toString());
            puntosRestantes=100-puntosPorIncidencias;
            jLabel17.setText(puntosRestantes.toString());
            //Ocultar fila Id
            tblIncidentes.getColumnModel().getColumn(0).setMaxWidth(0);
            tblIncidentes.getColumnModel().getColumn(0).setMinWidth(0);
            tblIncidentes.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);
            tblIncidentes.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
            
        }catch(Exception ex){
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
        
    }

     public void cargarDatosAlumno(){
         //JOptionPane.showMessageDialog(AdministradorVentanas.pantallaModificarIncidencia, Utilidades.idAlumno);
         try{
            TrAlumno alumno = new TrAlumno();
            alumno=alumno.seleccionarPorNumeroDeControl(Utilidades.numeroDeControl.toString());
            if(alumno!=null){
               jLabel9.setText(alumno.getNombre()+" "+alumno.getApPaterno()+" "+alumno.getApMaterno());
               jLabel11.setText(String.valueOf(alumno.getGrado()));
               jLabel13.setText(String.valueOf(alumno.getGrupo()));
            }
         }catch(Exception ex){
             JOptionPane.showMessageDialog(AdministradorVentanas.pantallaAlumnosFalta, "Lo sentimos, Ocurrió un error. "+ex.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
         }
     }
     public boolean validarCampos(){
        try{
            boolean avanzar=true;
            String dia = String.valueOf(dtpFecha.getCalendar().get(Calendar.DAY_OF_MONTH));
            String mes = String.valueOf(dtpFecha.getCalendar().get(Calendar.MONTH)+1);
            String anio = String.valueOf(dtpFecha.getCalendar().get(Calendar.YEAR));
            if(mes.length()==1){
                mes="0"+mes;
            }
            if(dia.length()==1){
                dia="0"+dia;
            }
            String fechaCompleta = dia+"/"+mes+"/"+anio;
            DateFormat formato = DateFormat.getDateInstance(DateFormat.SHORT);
            if(formato.parse(fechaCompleta)==null){
                JOptionPane.showMessageDialog(this, "El campo Fecha no debe ir vacío y debe ser una fecha en formato dd/mm/yyyy. \n Por favor llene este campo","Error",JOptionPane.ERROR_MESSAGE);
                avanzar=false;
            }else{
                    if(cmbTipo.getSelectedIndex()==0){
                        JOptionPane.showMessageDialog(this, "El campo Tipo no debe ir vacío. \n Por favor llene este campo","Error",JOptionPane.ERROR_MESSAGE);
                        avanzar=false;
                    }
                
            }
            return avanzar;
        }
        catch(ParseException ex){
            JOptionPane.showMessageDialog(this, "El campo Fecha no debe ir vacío y debe ser una fecha en formato dd/mm/yyyy. \n Por favor llene este campo","Error: "+ex.getMessage(),JOptionPane.ERROR_MESSAGE);
            return false;
        }
        catch(Exception ex){
            JOptionPane.showMessageDialog(this, "Error al validar los campos. \n Por favor contrate al administrador del sistema","Error: "+ex.getMessage(),JOptionPane.ERROR_MESSAGE);
            return false;
        }
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblIncidentes = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        dtpFecha = new com.toedter.calendar.JDateChooser();
        jLabel2 = new javax.swing.JLabel();
        cmbHora = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        cmbMinutos = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        cmbTipo = new javax.swing.JComboBox();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtDetalles = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel2.setBackground(new java.awt.Color(204, 204, 204));
        jPanel2.setMaximumSize(new java.awt.Dimension(900, 450));
        jPanel2.setMinimumSize(new java.awt.Dimension(900, 450));
        jPanel2.setPreferredSize(new java.awt.Dimension(900, 450));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jScrollPane1.setName("tblHistorial"); // NOI18N

        tblIncidentes.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        tblIncidentes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblIncidentes.setName("tblHistorial"); // NOI18N
        tblIncidentes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblIncidentesMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblIncidentes);

        jPanel2.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 220, -1, 100));

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/controldepuntos/recursos/guardar.jpg"))); // NOI18N
        jButton1.setText("Guardar cambios");
        jButton1.setName("btnMIncidencias"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 350, -1, -1));

        jButton2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/controldepuntos/recursos/atras.jpg"))); // NOI18N
        jButton2.setText("Atras");
        jButton2.setName("btnSalir"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(790, 410, -1, -1));

        jButton3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/controldepuntos/recursos/alta.jpg"))); // NOI18N
        jButton3.setText("Agregar Incidente");
        jButton3.setName("btnAltaI"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 330, -1, -1));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("Fecha:");
        jLabel1.setName("lblFecha"); // NOI18N
        jPanel2.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(590, 120, -1, -1));
        jPanel2.add(dtpFecha, new org.netbeans.lib.awtextra.AbsoluteConstraints(650, 120, 150, -1));

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("Hora:");
        jLabel2.setName("lblHora"); // NOI18N
        jPanel2.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(600, 150, -1, -1));

        cmbHora.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cmbHora.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" }));
        jPanel2.add(cmbHora, new org.netbeans.lib.awtextra.AbsoluteConstraints(650, 150, -1, -1));

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel4.setText("Min:");
        jPanel2.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(710, 150, -1, -1));

        cmbMinutos.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cmbMinutos.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59" }));
        jPanel2.add(cmbMinutos, new org.netbeans.lib.awtextra.AbsoluteConstraints(750, 150, -1, -1));

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel8.setText("Tipo:");
        jPanel2.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(600, 180, -1, -1));

        cmbTipo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cmbTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--Seleccione una opción--" }));
        cmbTipo.setName("cmbFaltas"); // NOI18N
        cmbTipo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbTipoActionPerformed(evt);
            }
        });
        jPanel2.add(cmbTipo, new org.netbeans.lib.awtextra.AbsoluteConstraints(650, 180, 150, -1));

        txtDetalles.setColumns(20);
        txtDetalles.setRows(5);
        txtDetalles.setName("txtDetalles"); // NOI18N
        txtDetalles.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtDetallesKeyPressed(evt);
            }
        });
        jScrollPane3.setViewportView(txtDetalles);

        jPanel2.add(jScrollPane3, new org.netbeans.lib.awtextra.AbsoluteConstraints(650, 220, 230, 110));

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel3.setText("Detalles:");
        jLabel3.setName("lblDetalles"); // NOI18N
        jPanel2.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(580, 220, -1, -1));

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel5.setText("Nombre del alumno: ");
        jPanel2.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 110, -1, -1));

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel9.setText("label9");
        jPanel2.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 110, 360, -1));

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel10.setText("Grado:");
        jPanel2.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 140, -1, -1));

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel11.setText("label11");
        jPanel2.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 140, 90, -1));

        jLabel12.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel12.setText("Grupo:");
        jPanel2.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 170, -1, -1));

        jLabel13.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel13.setText("label13");
        jPanel2.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 170, 100, -1));

        jLabel14.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel14.setText("Puntos por incidentes:");
        jPanel2.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 140, -1, -1));

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel15.setForeground(new java.awt.Color(255, 0, 0));
        jLabel15.setText("label15");
        jPanel2.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 140, -1, -1));

        jLabel16.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel16.setText("Puntos restantes:");
        jPanel2.add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 170, -1, -1));

        jLabel17.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel17.setForeground(new java.awt.Color(255, 0, 0));
        jLabel17.setText("label17");
        jLabel17.setToolTipText("");
        jPanel2.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 170, -1, -1));

        jLabel18.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        jLabel18.setText("Historial");
        jPanel2.add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 30, -1, -1));

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/controldepuntos/recursos/LogoSIAPPSuperChico.jpg"))); // NOI18N
        jPanel2.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(810, 10, -1, -1));

        jButton4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/controldepuntos/recursos/bote.jpg"))); // NOI18N
        jButton4.setText("Eliminar Incidente");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 330, -1, -1));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cmbTipoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbTipoActionPerformed
        if(cmbTipo.getSelectedIndex()==-1){
            idReglamento = Integer.parseInt(cmbTipo.getSelectedItem().toString());
            JOptionPane.showMessageDialog(AdministradorVentanas.pantallaAltaIncidencia, "Valor actual: "+idReglamento);
        }
    }//GEN-LAST:event_cmbTipoActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        AdministradorVentanas.pantallaAltaIncidencia=null;
        AdministradorVentanas.mostrarPantallaAltaIncidencia();
        AdministradorVentanas.ocultarPantallaModificarIncidencia();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        AdministradorVentanas.ocultarPantallaModificarIncidencia();
        AdministradorVentanas.mostrarPantallaAlumnosFalta();
        //AdministradorVentanas.mostrarPantallaMenu();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void tblIncidentesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblIncidentesMouseClicked
        try{
            filaSeleccionada=this.tblIncidentes.getSelectedRow();
            idSeleccionado=tblIncidentes.getModel().getValueAt(filaSeleccionada, 0);
            //JOptionPane.showMessageDialog(AdministradorVentanas.pantallaAlumnos, idSeleccionado.toString());
            TrIncidente incidenteEncontrado = new TrIncidente();
            incidenteEncontrado = incidenteEncontrado.seleccionarPorId(idSeleccionado.toString());
            DateFormat formato = DateFormat.getDateInstance(DateFormat.SHORT);
            Date fecha = formato.parse(incidenteEncontrado.getFecha());
            dtpFecha.setDate(fecha);
            String hora = incidenteEncontrado.getHora().toString().split(":")[0];
            String minutos = incidenteEncontrado.getHora().toString().split(":")[1];
            cmbHora.setSelectedItem(hora);
            cmbMinutos.setSelectedItem(minutos);
            cmbTipo.setSelectedItem(obtenerDescripcionDeReglamentoPorId(incidenteEncontrado.getIdIncidente()));
            txtDetalles.setText(incidenteEncontrado.getObservaciones());
        }catch(Exception ex){
            JOptionPane.showMessageDialog(AdministradorVentanas.pantallaModificarIncidencia, "Lo sentimos, Ocurrió un error. ARCatalogoFalta.jTable1MouseClicked"+ex.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_tblIncidentesMouseClicked

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        try{
            TrIncidente incidenteAEliminar = new TrIncidente();
            incidenteAEliminar.setIdIncidente(Integer.parseInt(idSeleccionado.toString()));
            incidenteAEliminar.eliminarIncidente(incidenteAEliminar);
        }catch(Exception ex){
            JOptionPane.showMessageDialog(AdministradorVentanas.pantallaAlumnos, "Lo sentimos, Ocurrió un error. ARCatalogoFalta.jTable1MouseClicked"+ex.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
         try{
             if((Integer)idSeleccionado==0){
                 JOptionPane.showMessageDialog(this, "Debe seleccionar un elemento de la tabla.","Error",JOptionPane.ERROR_MESSAGE);
             }else{
                 if(validarCampos()){
                    //JOptionPane.showMessageDialog(this, "HOLA");
                    TrIncidente incidenteAModificar = new TrIncidente();
                    //JOptionPane.showMessageDialog(this, "Id alumno actual: "+Utilidades.idAlumno);
                    //incidenteAModificar.setIdAlumno(Utilidades.idAlumno);
                    incidenteAModificar.setIdIncidente(Integer.parseInt(idSeleccionado.toString()));
                    incidenteAModificar.setIdReglamento(obtenerIdDeReglamentoSeleccionado(cmbTipo.getSelectedItem().toString()));
                    String dia = String.valueOf(dtpFecha.getCalendar().get(Calendar.DAY_OF_MONTH));
                    String mes = String.valueOf(dtpFecha.getCalendar().get(Calendar.MONTH)+1);
                    String anio = String.valueOf(dtpFecha.getCalendar().get(Calendar.YEAR));
                    if(mes.length()==1){
                        mes="0"+mes;
                    }
                    if(dia.length()==1){
                        dia="0"+dia;
                    }
                    String fechaCompleta = dia+"/"+mes+"/"+anio;
                    //String fechaCompleta = anio+"-"+mes+"-"+dia;
                    //JOptionPane.showMessageDialog(this, "Fecha actual: "+fechaCompleta);
                    //DateFormat formato = DateFormat.getDateInstance(DateFormat.SHORT);
                    DateFormat formato = DateFormat.getDateInstance(DateFormat.SHORT);
                    //Se convierte. Si truena aquí significa que hay un error en la fecha
                    formato.parse(fechaCompleta);
                    //JOptionPane.showMessageDialog(this, "Fecha convertida: "+fecha);
                    //DateFormat formato2 = DateFormat.getDateInstance(DateFormat.SHORT);
                    incidenteAModificar.setFecha(fechaCompleta);
                    //JOptionPane.showMessageDialog(this, "Fecha asignada: "+incidenteAInsertar.getFecha());
                    String hora = cmbHora.getSelectedItem().toString()+":"+cmbMinutos.getSelectedItem().toString()+":00";
                    //JOptionPane.showMessageDialog(this, "Hora actual: "+hora);
                    incidenteAModificar.setHora(Time.valueOf(hora));
                    incidenteAModificar.setObservaciones(txtDetalles.getText());
                    incidenteAModificar.modificarIncidente(incidenteAModificar);
                 }
             }
        }catch(Exception ex){
            JOptionPane.showMessageDialog(this, "Lo sentimos, ocurrió un error"+ex.getMessage()+ex.getStackTrace(),"Error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void txtDetallesKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDetallesKeyPressed
        Utilidades.establecerLongitudMaxima(txtDetalles, evt, 500);
    }//GEN-LAST:event_txtDetallesKeyPressed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ModificarIncidencia.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ModificarIncidencia.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ModificarIncidencia.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ModificarIncidencia.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ModificarIncidencia().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cmbHora;
    private javax.swing.JComboBox cmbMinutos;
    private javax.swing.JComboBox cmbTipo;
    private com.toedter.calendar.JDateChooser dtpFecha;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable tblIncidentes;
    private javax.swing.JTextArea txtDetalles;
    // End of variables declaration//GEN-END:variables
}
